function state=generateTatetiState()
    global BOARD_SIZE;
    clc;
    
    MAX_GAME    = 8;
    MAX_POS     = 2;
    BOARD_SIZE  = 3;
    PLAYERS     = 2;

    games=round(rand()*MAX_GAME)+1
    state=zeros(BOARD_SIZE,BOARD_SIZE);

    x=round(rand()*MAX_POS)+1;
    y=round(rand()*MAX_POS)+1;

    while(games > 0 && goal(state)==0)

            while(state(x,y)>0)
                x=round(rand()*MAX_POS)+1;
                y=round(rand()*MAX_POS)+1;
            end

            state(x,y)=mod(games,2)+1;

            games=games-1;
    end
    
    winner=goal(state);
    
    if(winner>0)
        display(strcat('gano_',int2str(winner)));
    end
    
end

function player=goal(state)
    global BOARD_SIZE;
    
    PLAYER1=1;
    PLAYER2=2;

    if(win(state,PLAYER1)>0)
        player=PLAYER1;
    else
        if(win(state,PLAYER2)>0)
           player=PLAYER2;
        else
            player=0;
        end
    end
    % empate?
end

